<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head><meta name="generator" content="Hexo 3.8.0">

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Description-->

    

    
        <meta name="description" content="为了更好的根据具体情况显示YUV420的视频帧和RGB的视频帧，我们先创建一个基类Video_Render：123456789101112131415161718192021222324252627282930313233//video_render.h#ifndef VIDEO_RENDER_H#">
    

    <!--Author-->
    
        <meta name="author" content="Cyrus">
    

    <!--Open Graph Title-->
    
        <meta property="og:title" content="QT OpenGL渲染RGB格式数据">
    

    <!--Open Graph Description-->
    
        <meta property="og:description" content="为了更好的根据具体情况显示YUV420的视频帧和RGB的视频帧，我们先创建一个基类Video_Render：123456789101112131415161718192021222324252627282930313233//video_render.h#ifndef VIDEO_RENDER_H#">
    

    <!--Open Graph Site Name-->
        <meta property="og:site_name" content="Cyrus的技术空间">

    <!--Type page-->
    
        <meta property="og:type" content="article">
    

    <!--Page Cover-->
    
    
        <meta property="og:image" content="http://cyrus_huang.gitee.io/bloghttp://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg">
    

        <meta name="twitter:card" content="summary_large_image">

    

    
        <meta name="twitter:image" content="http://cyrus_huang.gitee.io/bloghttp://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg">
    

    <!-- Title -->
    
    <title>QT OpenGL渲染RGB格式数据 - Cyrus的技术空间</title>

    <!-- Bootstrap Core CSS -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/blog/css/style.css">

    <!-- Custom Fonts -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Gallery -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.css" type="text/css" rel="stylesheet">

    <!-- Google Analytics -->
    


    <!-- favicon -->
    

</head>


<body>

    <!-- Menu -->
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/blog/">Cyrus的技术空间</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                
                    <li>
                        <a href="/blog/">
                            
                                Home
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/archives">
                            
                                Archives
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/tags">
                            
                                Tags
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/categories">
                            
                                Categories
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="https://github.com/klugjo/hexo-theme-clean-blog">
                            
                                <i class="fa fa-github fa-stack-2x"></i>
                            
                        </a>
                    </li>
                
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

    <!-- Main Content -->
    <!-- Page Header -->
<!-- Set your background image for this header in your post front-matter: cover -->

<header class="intro-header" style="background-image: url('http://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <h1>QT OpenGL渲染RGB格式数据</h1>
                    
                    <span class="meta">
                        <!-- Date and Author -->
                        
                            Posted by Cyrus on
                        
                        
                            2019-10-06
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Tags and categories -->
           
                <div class="col-lg-4 col-lg-offset-2 col-md-5 col-md-offset-1 post-tags">
                    
                        


<a href="/blog/tags/QT/">#QT</a>


                    
                </div>
                <div class="col-lg-4 col-md-5 post-categories">
                    
                        

<a href="/blog/categories/播放器/">播放器</a>

                    
                </div>
            

            <!-- Gallery -->
            

            <!-- Post Main Content -->
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <p>为了更好的根据具体情况显示YUV420的视频帧和RGB的视频帧，我们先创建一个基类Video_Render：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">//video_render.h</span><br><span class="line">#ifndef VIDEO_RENDER_H</span><br><span class="line">#define VIDEO_RENDER_H</span><br><span class="line"></span><br><span class="line">#include &lt;QObject&gt;</span><br><span class="line">#include &lt;QOpenGLWidget&gt;</span><br><span class="line">#include &lt;QOpenGLFunctions&gt;</span><br><span class="line">#include &lt;QOpenGLShaderProgram&gt;</span><br><span class="line"></span><br><span class="line">class Video_Render: protected QOpenGLFunctions</span><br><span class="line">&#123;</span><br><span class="line">public:</span><br><span class="line">    Video_Render();</span><br><span class="line">    virtual ~Video_Render();</span><br><span class="line"></span><br><span class="line">    virtual void initialize() = 0;</span><br><span class="line">    virtual void render(uchar* ptr,int width,int height,int type) = 0;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">#endif // VIDEO_RENDER_H</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">// video_render.cpp</span><br><span class="line">#include &quot;video_render.h&quot;</span><br><span class="line">Video_Render::Video_Render()</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">Video_Render::~Video_Render()</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>修改YUV420_Render,使之继承Video_Render<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">#ifndef YUV420_RENDER_H</span><br><span class="line">#define YUV420_RENDER_H</span><br><span class="line"></span><br><span class="line">#include &quot;video_render.h&quot;</span><br><span class="line"></span><br><span class="line">class YUV420_Render: public Video_Render</span><br><span class="line">&#123;</span><br><span class="line">public:</span><br><span class="line">    YUV420_Render();</span><br><span class="line">    ~YUV420_Render();</span><br><span class="line"></span><br><span class="line">        //初始化gl</span><br><span class="line">        void initialize();</span><br><span class="line">        //刷新显示</span><br><span class="line">        void render(uchar* py,uchar* pu,uchar* pv,int width,int height,int type);</span><br><span class="line">        void render(uchar* ptr,int width,int height,int type);</span><br><span class="line"></span><br><span class="line">    private:</span><br><span class="line">        //shader程序</span><br><span class="line">        QOpenGLShaderProgram m_program;</span><br><span class="line">        //shader中yuv变量地址</span><br><span class="line">        GLuint m_textureUniformY, m_textureUniformU , m_textureUniformV;</span><br><span class="line">        //创建纹理</span><br><span class="line">        GLuint m_idy , m_idu , m_idv;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">#endif // YUV420_RENDER_H</span><br></pre></td></tr></table></figure></p>
<p>创建RGB_Render，同样继承Video_Render<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br></pre></td><td class="code"><pre><span class="line">// rgb_render.h</span><br><span class="line">#ifndef RGB_RENDER_H</span><br><span class="line">#define RGB_RENDER_H</span><br><span class="line"></span><br><span class="line">#include &quot;video_render.h&quot;</span><br><span class="line"></span><br><span class="line">class RGB_Render: public Video_Render</span><br><span class="line">&#123;</span><br><span class="line">public:</span><br><span class="line">    RGB_Render();</span><br><span class="line">    ~RGB_Render();</span><br><span class="line"></span><br><span class="line">    //初始化gl</span><br><span class="line">    void initialize();</span><br><span class="line">    //刷新显示</span><br><span class="line">    void render(uchar* ptr,int width,int height,int type);</span><br><span class="line"></span><br><span class="line">private:</span><br><span class="line">    //shader程序</span><br><span class="line">    QOpenGLShaderProgram m_program;</span><br><span class="line">    //shader中yuv变量地址</span><br><span class="line">    GLuint m_textureUniform;</span><br><span class="line">    //创建纹理</span><br><span class="line">    GLuint m_id;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">#endif // RGB_RENDER_H</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">// rgb_render.cpp</span><br><span class="line">#include &quot;rgb_render.h&quot;</span><br><span class="line"></span><br><span class="line">#define ATTRIB_VERTEX 0</span><br><span class="line">#define ATTRIB_TEXTURE 1</span><br><span class="line"></span><br><span class="line">RGB_Render::RGB_Render()</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">RGB_Render::~RGB_Render()</span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//初始化gl</span><br><span class="line">void RGB_Render::initialize()</span><br><span class="line">&#123;</span><br><span class="line">    qDebug() &lt;&lt; &quot;initializeGL&quot;;</span><br><span class="line"></span><br><span class="line">    //初始化opengl （QOpenGLFunctions继承）函数</span><br><span class="line">    initializeOpenGLFunctions();</span><br><span class="line"></span><br><span class="line">    //顶点shader</span><br><span class="line">    const char *vString =</span><br><span class="line">            &quot;attribute vec4 vertexPosition;\</span><br><span class="line">            attribute vec2 textureCoordinate;\</span><br><span class="line">    varying vec2 texture_Out;\</span><br><span class="line">    void main(void)\</span><br><span class="line">    &#123;\</span><br><span class="line">        gl_Position = vertexPosition;\</span><br><span class="line">        texture_Out = textureCoordinate;\</span><br><span class="line">    &#125;&quot;;</span><br><span class="line">    //片元shader</span><br><span class="line">    const char *tString =</span><br><span class="line">            &quot;varying vec2 texture_Out;\</span><br><span class="line">            uniform sampler2D tex;\</span><br><span class="line">    void main(void)\</span><br><span class="line">    &#123;\</span><br><span class="line">        gl_FragColor = texture2D(tex, texture_Out); \</span><br><span class="line">    &#125;&quot;;</span><br><span class="line"></span><br><span class="line">    //m_program加载shader（顶点和片元）脚本</span><br><span class="line">    //片元（像素）</span><br><span class="line">    qDebug()&lt;&lt;m_program.addShaderFromSourceCode(QOpenGLShader::Fragment, tString);</span><br><span class="line">    //顶点shader</span><br><span class="line">    qDebug() &lt;&lt; m_program.addShaderFromSourceCode(QOpenGLShader::Vertex, vString);</span><br><span class="line"></span><br><span class="line">    //设置顶点位置</span><br><span class="line">    m_program.bindAttributeLocation(&quot;vertexPosition&quot;,ATTRIB_VERTEX);</span><br><span class="line">    //设置纹理位置</span><br><span class="line">    m_program.bindAttributeLocation(&quot;textureCoordinate&quot;,ATTRIB_TEXTURE);</span><br><span class="line"></span><br><span class="line">    //编译shader</span><br><span class="line">    qDebug() &lt;&lt; &quot;m_program.link() = &quot; &lt;&lt; m_program.link();</span><br><span class="line"></span><br><span class="line">    qDebug() &lt;&lt; &quot;m_program.bind() = &quot; &lt;&lt; m_program.bind();</span><br><span class="line"></span><br><span class="line">    //传递顶点和纹理坐标</span><br><span class="line">    //顶点</span><br><span class="line">    static const GLfloat ver[] = &#123;</span><br><span class="line">        -1.0f,-1.0f,</span><br><span class="line">        1.0f,-1.0f,</span><br><span class="line">        -1.0f, 1.0f,</span><br><span class="line">        1.0f,1.0f</span><br><span class="line">        //        -1.0f,-1.0f,</span><br><span class="line">        //        0.9f,-1.0f,</span><br><span class="line">        //        -1.0f, 1.0f,</span><br><span class="line">        //        0.9f,1.0f</span><br><span class="line">    &#125;;</span><br><span class="line">    //纹理</span><br><span class="line">    static const GLfloat tex[] = &#123;</span><br><span class="line">        0.0f, 1.0f,</span><br><span class="line">        1.0f, 1.0f,</span><br><span class="line">        0.0f, 0.0f,</span><br><span class="line">        1.0f, 0.0f</span><br><span class="line">    &#125;;</span><br><span class="line"></span><br><span class="line">    //设置顶点,纹理数组并启用</span><br><span class="line">    glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, ver);</span><br><span class="line">    glEnableVertexAttribArray(ATTRIB_VERTEX);</span><br><span class="line">    glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, tex);</span><br><span class="line">    glEnableVertexAttribArray(ATTRIB_TEXTURE);</span><br><span class="line"></span><br><span class="line">    //从shader获取地址</span><br><span class="line">    m_textureUniform = m_program.uniformLocation(&quot;tex&quot;);</span><br><span class="line"></span><br><span class="line">    //创建纹理</span><br><span class="line">    glGenTextures(1, &amp;m_id);</span><br><span class="line">    //只需要一个texture</span><br><span class="line">    glBindTexture(GL_TEXTURE_2D, m_id);</span><br><span class="line">    //放大过滤，线性插值   GL_NEAREST(效率高，但马赛克严重)</span><br><span class="line">    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);</span><br><span class="line">    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);</span><br><span class="line"></span><br><span class="line">    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);</span><br><span class="line">    glClear(GL_COLOR_BUFFER_BIT);</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">void RGB_Render::render(uchar* ptr,int width,int height,int type)</span><br><span class="line">&#123;</span><br><span class="line">    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);</span><br><span class="line">    glClear(GL_COLOR_BUFFER_BIT);</span><br><span class="line"></span><br><span class="line">    glActiveTexture(GL_TEXTURE0);</span><br><span class="line">    glBindTexture(GL_TEXTURE_2D, m_id);</span><br><span class="line">    //修改纹理内容(复制内存内容)</span><br><span class="line">    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE,ptr);</span><br><span class="line">    //与shader 关联</span><br><span class="line">    glUniform1i(m_textureUniform, 0);</span><br><span class="line"></span><br><span class="line">    glDrawArrays(GL_TRIANGLE_STRIP,0,4);</span><br><span class="line">    qDebug() &lt;&lt; &quot;paintGL&quot;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>修改MyOpenGLWidget<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line">#ifndef MYOPENGLWIDGET_H</span><br><span class="line">#define MYOPENGLWIDGET_H</span><br><span class="line"></span><br><span class="line">#include &lt;QOpenGLWidget&gt;</span><br><span class="line">#include &quot;video_render.h&quot;</span><br><span class="line">#include &quot;mpvideoframe.h&quot;</span><br><span class="line"></span><br><span class="line">class MyOpenGLWidget : public QOpenGLWidget</span><br><span class="line">&#123;</span><br><span class="line">    Q_OBJECT</span><br><span class="line">public:</span><br><span class="line">    explicit MyOpenGLWidget(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());</span><br><span class="line">    void setFrame(MPVideoFrame *frame);</span><br><span class="line"></span><br><span class="line">protected:</span><br><span class="line"></span><br><span class="line">    void initializeGL();</span><br><span class="line">    void paintGL();</span><br><span class="line">    void resizeGL(int w, int h);</span><br><span class="line"></span><br><span class="line">private:</span><br><span class="line">    Video_Render *pRender;</span><br><span class="line">    MPVideoFrame  *pCurrentFrame;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">#endif // MYOPENGLWIDGET_H</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#include &quot;myopenglwidget.h&quot;</span><br><span class="line">#include &quot;rgb_render.h&quot;</span><br><span class="line">#include &quot;yuv420_render.h&quot;</span><br><span class="line"></span><br><span class="line">MyOpenGLWidget::MyOpenGLWidget(QWidget *parent, Qt::WindowFlags f) : QOpenGLWidget(parent, f)</span><br><span class="line">&#123;</span><br><span class="line">    pRender = new RGB_Render();</span><br><span class="line">    pCurrentFrame = NULL;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">void MyOpenGLWidget::initializeGL()</span><br><span class="line">&#123;</span><br><span class="line">    pCurrentFrame = NULL;</span><br><span class="line">    pRender-&gt;initialize();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">void MyOpenGLWidget::setFrame(MPVideoFrame *frame)</span><br><span class="line">&#123;</span><br><span class="line">    if(this-&gt;pCurrentFrame != NULL) &#123;</span><br><span class="line">        delete this-&gt;pCurrentFrame;</span><br><span class="line">    &#125;</span><br><span class="line">    this-&gt;pCurrentFrame = frame;</span><br><span class="line">    update();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">void MyOpenGLWidget::paintGL()</span><br><span class="line">&#123;</span><br><span class="line">    if(pCurrentFrame == NULL) &#123;</span><br><span class="line">        return;</span><br><span class="line">    &#125;</span><br><span class="line">//    pRender-&gt;render(pCurrentFrame-&gt;yData, pCurrentFrame-&gt;uData, pCurrentFrame-&gt;vData, pCurrentFrame-&gt;width, pCurrentFrame-&gt;height, 0);</span><br><span class="line">    pRender-&gt;render(pCurrentFrame-&gt;databuffer, pCurrentFrame-&gt;width, pCurrentFrame-&gt;height, 0);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">void MyOpenGLWidget::resizeGL(int w, int h)</span><br><span class="line">&#123;</span><br><span class="line">    glViewport(0, 0, w, h);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>


                
            </div>

            <!-- Comments -->
            
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    


                </div>
            
        </div>
    </div>
</article>

    <!-- Footer -->
    <hr>

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                    

                    

                    
                        <li>
                            <a href="https://github.com/klugjo/hexo-theme-clean-blog" target="_blank">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    

                    

                    

                    
                </ul>
                <p class="copyright text-muted">&copy; 2020 Cyrus<br></p>
                <p class="copyright text-muted">Original Theme <a target="_blank" href="http://startbootstrap.com/template-overviews/clean-blog/">Clean Blog</a> from <a href="http://startbootstrap.com/" target="_blank">Start Bootstrap</a></p>
                <p class="copyright text-muted">Adapted for <a target="_blank" href="https://hexo.io/">Hexo</a> by <a href="http://www.codeblocq.com/" target="_blank">Jonathan Klughertz</a></p>
                <p class="copyright text-muted"><a href="http://www.beian.miit.gov.cn">粤ICP备18110122号-1</a></p>
            </div>
        </div>
    </div>
</footer>


    <!-- After footer scripts -->
    
<!-- jQuery -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Bootstrap -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- Gallery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.js" type="text/javascript" charset="utf-8"></script>

<!-- Disqus Comments -->



</body>

</html>